/**
 *
 */
package com.naiterui.ehp.bs.recommend.remote;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bp.utils.lang.ConfigUtil;
import com.naiterui.ehp.bp.utils.net.RestHttpUtil;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service;

/**
 * @author guoyongxiang
 * @since 2.9.0
 */
@Service
@RequiredArgsConstructor
public class RecomWeixinRemoter implements IRecomWeixinRemoter {

    private final String checkDrTokenUrl = ConfigUtil.getString("dr.check.token.url");
    private final String checkMiniappTokenUrl = ConfigUtil.getString("miniapp.check.token.url");
    private final String checkDoctorPcTokenUrl = ConfigUtil.getString("doctor.pc.token.url");

    @Override
    public boolean checkDrToken(String doctorId, String token) throws BusinessException {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("doctorId", doctorId);
        paramMap.put("token", token);
        return RestHttpUtil.post()
                .url(checkDrTokenUrl)
                .paramMap(paramMap)
                .executeData(new ParameterizedTypeReference<ResponseVO<Boolean>>() {
                });

    }

    @Override
    public Long checkMiniToken(String token) throws BusinessException {
        Map map = new HashMap();
        map.put(SettingConfig.TOKEN_HEADER, token);
        return RestHttpUtil.post()
                .url(checkMiniappTokenUrl)
                .header(map)
                .executeData(new ParameterizedTypeReference<ResponseVO<Long>>() {
                });
    }

    @Override
    public Long checkDoctorPcToken(String token) throws BusinessException {
        Map map = new HashMap();
        map.put(SettingConfig.TOKEN_HEADER, token);
        return RestHttpUtil.get()
                .url(checkDoctorPcTokenUrl)
                .header(map)
                .executeData(new ParameterizedTypeReference<ResponseVO<Long>>() {
                });
    }
}
